import program = require('commander');
import { LayaI18N } from './LayaI18N';
const myPackage = require('../package.json');

interface CmdOption {
    name?: string;
    cfgRoot?: string;
    workspace?: string;
}

const rmQuotes = (val: string): string => {
    let rst = val.match(/(['"])(.+)\1/);
    if(rst) return rst[2];

    return val;
}

program
	.version(myPackage.version, "-v, --version")
	.option("-n, --name <string>", "[MUST] project path.", rmQuotes)
	.option("-c, --cfgRoot <path>", "[MUST] configuration root path.", rmQuotes)
	.option("-w, --workspace <path>", "[MUST] workspace path.", rmQuotes)
    .parse(process.argv);

let opts = program.opts() as CmdOption;
console.log(`cmd options: ${JSON.stringify(opts)}`);

if(!opts.name) {
    console.warn("The --name option is MUST.");
    program.help({error:true});
}
if(!opts.cfgRoot) {
    console.warn("The --cfgRoot option is MUST.");
    program.help({error:true});
}
if(!opts.workspace) {
    console.warn("The --workspace option is MUST.");
    program.help({error:true});
}

let i18n = new LayaI18N();
i18n.process(opts.name, opts.cfgRoot, opts.workspace);
